package com.np.shop.controller;


import com.np.shop.entity.TbBrand;
import com.np.shop.service.ITbBrandService;
import com.np.shop.utils.Result;
import com.np.shop.utils.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.locks.ReadWriteLock;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李高帅
 * @since 2020-11-27
 */
@CrossOrigin
@RestController
@RequestMapping("/shop")
@Slf4j
public class TbBrandController {
    @Autowired
    private ITbBrandService tbBrandService;

    /**
     * 品牌的列表
     * @return
     */
    @GetMapping("/findAll")
    public List<TbBrand> findAll(){
        List<TbBrand> tbBrands=tbBrandService.findBrand();
        return tbBrands;
    }

    /**
     * 品牌的回显
     * @param id
     * @return
     */
    @GetMapping("/getId/{id}")
    public TbBrand tbBrand(@PathVariable Long id){
        log.trace("回显id成功");
        return tbBrandService.getBrand(id);
    }

    /**
     * 品牌添加
     * @param tbBrand
     * @return
     */
    @PostMapping("/addBrand")
    public  boolean addBrand(@RequestBody  TbBrand tbBrand){
        log.trace("添加成功");
        boolean b=tbBrandService.save(tbBrand);
        return b;
    }

    /**
     * 品牌的删除
     * @param id
     */
    @DeleteMapping("/deleteById/{id}")
    public void deleteById(@PathVariable long id){
        log.trace("删除成功");
        tbBrandService.deleteById(id);
    }
}
